/**
 * Airport.java
 * Dec 29, 2009
 */
package com.dlplay.flightinfo.data;

import javax.jdo.annotations.Persistent;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * @author zhao yu
 *
 */
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Table(name = "airport")
public class Airport  extends DataEntryBase{
	

	private AirportTerminalCode code;
	private String location;
	private String description;
	
	private Weather weather;
	
	/**
	 * @param name
	 * @param identifier
	 */
	public Airport() {
		super();
//		this.name = name;
//		this.identifier = identifier;
//		this.name = null;
//		this.weather = new Weather();
	}
	
	public Airport(AirportTerminalCode code)
	{
		super();
		this.code = code;		
	}
	
	/**
	 * @param name
	 * @param identifier
	 */
	public Airport(AirportTerminalCode code, Weather weather) {
//		super();
		this.code = code;
		this.weather = weather;
	}

	
	/**
	 * @return the identifier
	 */
	@Column(name = "identifier")
	public AirportTerminalCode getIdentifier() {
		return code;
	}
	/**
	 * @param identifier the identifier to set
	 */
	public void setIdentifier(AirportTerminalCode code) {
		this.code = code;
	}
	/**
	 * @return the location
	 */
	@Column(name = "location", length = 60)
	public String getLocation() {
		return location;
	}
	/**
	 * @param location the location to set
	 */
	public void setLocation(String location) {
		this.location = location;
	}
	/**
	 * @return the description
	 */
	@Column(name = "description", length = 100)
	public String getDescription() {
		return description;
	}
	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}
	/**
	 * @return the temperature
	 */
	@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@Column(name = "weather")
//	@Transient
	public Weather getWeather() {
//		return new Weather();
		return weather;
	}
	/**
	 * @param temperature the temperature to set
	 */
	public void setWeather(Weather weather) {
		this.weather = weather;
	}
	
	//Utilities
	@Transient
	public void copy(Airport airport)
	{
		//TODO Add something here
		this.location = airport.getLocation();
		this.description = airport.getDescription();
		if (weather != null && airport.getWeather() != null)
		weather.copy(airport.getWeather());

	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Airport [code=" + code + ", description=" + description
				+ ", location=" + location + ", weather="
				+ weather + ", toString()=" + super.toString() + "]";
	}
	
}
